package com.taobao.txc.parser.struct;

import com.alibaba.fastjson.annotation.JSONField;
import com.taobao.txc.resourcemanager.b.a.a;
import java.sql.Connection;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class TxcTable
{
  @JSONField(serialize=false)
  private k a;
  public String schemaName;
  public String tableName;
  public String alias;
  @JSONField(serialize=false)
  private List<TxcLine> b = new ArrayList();
  public TxcLine[] line;
  
  public void a()
  {
    this.b.clear();
  }
  
  public int b()
  {
    return this.b.size();
  }
  
  public List<TxcLine> c()
  {
    return this.b;
  }
  
  public void a(ResultSet paramResultSet, ResultSetMetaData paramResultSetMetaData, int paramInt)
  {
    ArrayList localArrayList = new ArrayList(paramInt);
    for (int i = 1; i <= paramInt; i++)
    {
      String str = paramResultSetMetaData.getColumnName(i).toUpperCase();
      f localf = this.a.c(str);
      TxcField localTxcField = new TxcField();
      localTxcField.a(localf.b());
      localTxcField.a(localf.c());
      switch (localf.c())
      {
      case 91: 
        try
        {
          Date localDate = paramResultSet.getDate(i);
          if ("YEAR".equalsIgnoreCase(localf.d()))
          {
            localTxcField.a(4);
            localTxcField.a(localDate == null ? null : Integer.valueOf(localDate.getYear() + 1900));
          }
          else
          {
            localTxcField.a(localDate);
          }
        }
        catch (SQLException localSQLException1)
        {
          if (localSQLException1.getMessage().indexOf("'0000-00-00' can not be represented as java.sql.Date") != -1) {
            localTxcField.a(null);
          } else {
            throw localSQLException1;
          }
        }
        break;
      case 93: 
        try
        {
          localTxcField.a(paramResultSet.getObject(i));
        }
        catch (SQLException localSQLException2)
        {
          if (localSQLException2.getMessage().indexOf("'0000-00-00 00:00:00' can not be represented as java.sql.Timestamp") != -1) {
            localTxcField.a(null);
          } else {
            throw localSQLException2;
          }
        }
        break;
      default: 
        localTxcField.a(paramResultSet.getObject(i));
      }
      localArrayList.add(localTxcField);
    }
    TxcLine localTxcLine = new TxcLine();
    localTxcLine.a(e());
    localTxcLine.a(localArrayList);
    this.b.add(localTxcLine);
  }
  
  public void a(a parama, String paramString)
  {
    this.b.clear();
    Connection localConnection = parama.b();
    Statement localStatement = null;
    ResultSet localResultSet = null;
    try
    {
      localStatement = localConnection.createStatement();
      localResultSet = localStatement.executeQuery(paramString);
      ResultSetMetaData localResultSetMetaData = localResultSet.getMetaData();
      int i = localResultSetMetaData.getColumnCount();
      while (localResultSet.next()) {
        a(localResultSet, localResultSetMetaData, i);
      }
    }
    catch (SQLException localSQLException)
    {
      throw localSQLException;
    }
    finally
    {
      if (localResultSet != null) {
        localResultSet.close();
      }
      if (localStatement != null) {
        localStatement.close();
      }
    }
  }
  
  public List<TxcField> d()
  {
    String str = e().h();
    return new j(this, str);
  }
  
  public k e()
  {
    return this.a;
  }
  
  public void a(k paramk)
  {
    this.a = paramk;
  }
  
  public String toString()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    for (int i = 0; i < this.b.size(); i++)
    {
      List localList = ((TxcLine)this.b.get(i)).a();
      Iterator localIterator = localList.iterator();
      while (localIterator.hasNext())
      {
        TxcField localTxcField = (TxcField)localIterator.next();
        switch (localTxcField.b())
        {
        case -15: 
        case -9: 
        case -6: 
        case -5: 
        case 1: 
        case 2: 
        case 4: 
        case 12: 
        case 2003: 
          localStringBuilder.append(localTxcField.c()).append(',');
        }
      }
    }
    return localStringBuilder.toString();
  }
  
  public String f()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    for (TxcLine localTxcLine : this.line) {
      localStringBuilder.append(localTxcLine.toString()).append("\n");
    }
    return localStringBuilder.toString();
  }
  
  public String g()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    for (int i = 0; i < this.b.size(); i++)
    {
      List localList = ((TxcLine)this.b.get(i)).a();
      Iterator localIterator = localList.iterator();
      while (localIterator.hasNext())
      {
        TxcField localTxcField = (TxcField)localIterator.next();
        localStringBuilder.append(localTxcField.c()).append(":");
      }
      localStringBuilder.append("\n");
    }
    return localStringBuilder.toString();
  }
  
  public void a(String paramString)
  {
    this.schemaName = paramString;
  }
  
  public String h()
  {
    return this.tableName;
  }
  
  public void b(String paramString)
  {
    this.tableName = paramString;
  }
  
  public void c(String paramString)
  {
    this.alias = paramString;
  }
}


/* Location:           C:\Users\ibm\Downloads\txc-yun-sample (1)\txc-yun-sample\lib\txc-client-2.0.72.jar
 * Qualified Name:     com.taobao.txc.parser.struct.TxcTable
 * JD-Core Version:    0.7.0.1
 */